<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>分析结果</title>
    <link rel="stylesheet" type="text/css" href="http://unpkg.com/view-design/dist/styles/iview.css">
    <script type="text/javascript" src="http://vuejs.org/js/vue.min.js"></script>
    <script type="text/javascript" src="http://unpkg.com/view-design/dist/iview.min.js"></script>
    <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body onload="f();newMsgCount();newRequestCount()">
<!--<h1>SUCCESS!</h1>-->
<div id="app">
    <!--    {{message}}-->
    <div class="layout">
        <layout :style="{minHeight: '100vh'}">
            <sider collapsible :collapsed-width="78" v-model="isCollapsed">
                <i-menu theme="dark" width="auto" :class="menuitemClasses" open-names="['1','2']">
                    <submenu name="1">
                        <template slot="title">
                            个人中心
                            <icon type="ios-paper"/>
                        </template>
                        <menu-item name="1-1"><span onclick="MoreInfo()">完善信息</span></menu-item>
                        <Badge :count="countMsg">
                            <menu-item name="1-2">
                            <span onclick="Board()">
                                留言板</span>
                            </menu-item></Badge>
                        <menu-item name="1-3">
                            <span onclick="Questions()">
                                调查问卷
                            </span></menu-item>
                        <menu-item name="1-4">
                            <span>
                                分析结果
                            </span></menu-item>
                    </submenu>
                    <submenu name="2">
                        <template slot="title">聊天室
                            <icon type="ios-people" />
                        </template>
                        <Badge :count="countNewRequest">
                            <menu-item name="2-1">
                                <span onclick="FriendList()">好友列表</span>
                            </menu-item></Badge>
                        <menu-item name="2-2">
                            <span onclick="chat()">聊天室</span>
                        </menu-item>
                    </submenu>
                </i-menu>
            </sider>
            <layout>
                <i-header :style="{background: '#fff', boxShadow: '0 2px 3px 2px rgba(0,0,0,.1)'}">
                    <div style="float: left;margin-left: 70%">
                        <h1>欢迎您 ! &nbsp;&nbsp; {{message}}</h1>
                    </div>
                    <a href="/Login" style="margin-left: 50px"> 注销</a>
                </i-header>
                <i-content :style="{padding: '0 16px 16px'}">
                    <breadcrumb :style="{margin: '16px 0'}">
                        {{info}}
                    </breadcrumb>
                    <card>
                        <h1>{{thanks}}</h1>
                        <div style="height: 100px;margin-top: 2%;margin-left: 5%;margin-right: 5%">
                            <p>{{result}}</p>
                        </div>
                        <div style="margin-left: 65%;margin-top: 15%">
                            <img src="/static/pic/cat.png" style="height: 250px;width: 250px">
                        </div>
                    </card>
                </i-content>
            </layout>
        </layout>
    </div>
</div>

<script>
    var uu;
    function f(){
        $.ajax({
            url:'/search',
            type:'get',
            success(res) {
                let msg=JSON.stringify(res);
                msg=$.parseJSON(msg);
                uu=msg;
                if(res.sname===null){
                    active("新用户!","请完善你的个人信息");
                    MoreInfo();
                }else{
                    active(msg.sname);
                    isFinished(msg.sno);
                }
            }
        })
    }
    function isFinished(sno) {
        $.ajax({
            url:'/stu/Questions/isFinished',
            type:'post',
            data:{
                "sno":sno
            },
            success(res) {
                if(res==="ok"){
                    getResult(sno);
                }else{
                    Questions();
                    console.log("hahahahaha")
                }
            }
        })
    }
    function getResult(sno) {
        $.ajax({
            url:'/stu/Questions/getResult',
            type:'post',
            data:{
                "sno":sno
            },
            success(res){
                mVue.thanks="感谢您参与我的调查问卷！你的测评分析为：";
                mVue.result=res
            }
        })
    }
    var mVue = new Vue({
        el:'#app',
        data(){
            return{
                countMsg:'',
                countNewRequest:'',
                message:'',
                info:'',
                isCollapsed: false,
                choose:'',
                result:'',
                thanks:''
            }
        },
        computed: {
            menuitemClasses: function () {
                return [
                    'menu-item',
                    this.isCollapsed ? 'collapsed-menu' : ''
                ]
            },
        },
        methods:{
        }
    });

    function active(res,ss) {
        mVue.message=res;
        mVue.info=ss;
    }
    function chat() {
        mVue.choose="chat";
        window.location.href="/stu/chat";
    }
    function Questions() {
        mVue.choose="Questions";
        window.location.href="/stu/Questions/";
    }
    function Board() {
        mVue.choose="Board";
        window.location.href="/stu/Board/";
    }
    function FriendList() {
        mVue.choose="FriendList";
        window.location.href="/stu/FriendList/";
    }
    function MoreInfo() {
        // mVue.choose="Questions";
        window.location.href="/stu/MoreInfo/";
    }
    function newMsgCount() {
        $.ajax({
            url:'/stu/newMsgCount',
            type:'post',
            success(res){
                mVue.countMsg=res;
                console.log(res);
            }
        })
    }
    function newRequestCount(){
        $.ajax({
            url:'/stu/newRequestCount',
            type:'post',
            success(res) {
                mVue.countNewRequest=res;
                console.log(res);
            }
        })
    }

</script>
</body>
</html>